package com.china.lottery.listener.dao.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.china.lottery.listener.code.base.AccountCode;

/**
 * LPayAccountHis entity. @author bati
 */
@Entity
@Table(name = "L_PAY_ACCOUNT_HIS")
public class LPayAccountHis implements java.io.Serializable {
	
	private static final long serialVersionUID = 1L;
	
	// ��Ч
	public static int STATUS_VALID = 1;
	
	// ��Ч
	public static int STATUS_INVALID = -1;
	
	public static int COMMIT_STATUS_NO = 0;
	public static int COMMIT_STATUS_YES = 1;

	// Fields

	private Long id;
	private Integer accountId;
	private String agentId;
	private String accountCode;
	private double debitCredit;
	private Long serviceId;
	private int status;
	private int commitStatus;
	private String createUser;
	private String remark;
	private Date createTime;
	private double balanceBefore;
	private double balanceAfter;
	// Constructors

	/** default constructor */
	public LPayAccountHis() {
	}

	/** minimal constructor */
	public LPayAccountHis(Long id, String agentId) {
		this.id = id;
		this.agentId = agentId;
	}

	/** full constructor */
	public LPayAccountHis(Long id, Integer accountId, String agentId,
			String accountCode, double debitCredit, Long serviceId, int status,
			int commitStatus, String createUser, String remark, Date createTime) {
		this.id = id;
		this.accountId = accountId;
		this.agentId = agentId;
		this.accountCode = accountCode;
		this.debitCredit = debitCredit;
		this.serviceId = serviceId;
		this.status = status;
		this.commitStatus = commitStatus;
		this.createUser = createUser;
		this.remark = remark;
		this.createTime = createTime;
	}

	// Property accessors
	@Id
	@SequenceGenerator(name = "S_PAY_ACCOUNT_HIS_GENERATOR", sequenceName = "S_PAY_ACCOUNT_HIS", allocationSize = 1)
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "S_PAY_ACCOUNT_HIS_GENERATOR")
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "ACCOUNT_ID", precision = 8, scale = 0)
	public Integer getAccountId() {
		return this.accountId;
	}

	public void setAccountId(Integer accountId) {
		this.accountId = accountId;
	}

	@Column(name = "AGENT_ID", nullable = false, length = 30)
	public String getAgentId() {
		return this.agentId;
	}

	public void setAgentId(String agentId) {
		this.agentId = agentId;
	}

	@Column(name = "ACCOUNT_CODE", length = 4)
	public String getAccountCode() {
		return this.accountCode;
	}

	public void setAccountCode(String accountCode) {
		this.accountCode = accountCode;
	}

	@Column(name = "DEBIT_CREDIT", precision = 12)
	public double getDebitCredit() {
		return this.debitCredit;
	}

	public void setDebitCredit(double debitCredit) {
		this.debitCredit = debitCredit;
	}

	@Column(name = "SERVICE_ID", precision = 10, scale = 0)
	public Long getServiceId() {
		return this.serviceId;
	}

	public void setServiceId(Long serviceId) {
		this.serviceId = serviceId;
	}

	@Column(name = "STATUS", precision = 2, scale = 0)
	public int getStatus() {
		return this.status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	@Column(name = "COMMIT_STATUS", precision = 2, scale = 0)
	public int getCommitStatus() {
		return this.commitStatus;
	}

	public void setCommitStatus(int commitStatus) {
		this.commitStatus = commitStatus;
	}

	@Column(name = "CREATE_USER", length = 200)
	public String getCreateUser() {
		return this.createUser;
	}

	public void setCreateUser(String createUser) {
		this.createUser = createUser;
	}

	@Column(name = "REMARK", length = 500)
	public String getRemark() {
		return this.remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATE_TIME")
	public Date getCreateTime() {
		return this.createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
	@Column(name = "BALANCE_BEFORE", precision = 12)
	public double getBalanceBefore() {
		return balanceBefore;
	}

	public void setBalanceBefore(double balanceBefore) {
		this.balanceBefore = balanceBefore;
	}

	@Column(name = "BALANCE_AFTER", precision = 12)
	public double getBalanceAfter() {
		return balanceAfter;
	}

	public void setBalanceAfter(double balanceAfter) {
		this.balanceAfter = balanceAfter;
	}

	@Override
	public String toString() {
		return "LPayAccountHis [id=" + id + ", accountId=" + accountId
				+ ", agentId=" + agentId + ", accountCode=" + accountCode
				+ ", debitCredit=" + debitCredit + ", serviceId=" + serviceId
				+ ", status=" + status + ", commitStatus=" + commitStatus
				+ ", createUser=" + createUser + ", remark=" + remark
				+ ", createTime=" + createTime + "]";
	}

	public static LPayAccountHis getCommit(LPayAccount account, double money,
			AccountCode code, long serviceId) {
		LPayAccountHis instance = new LPayAccountHis();
        instance.accountId = account.getId();
        instance.agentId = account.getAgentId();
        instance.debitCredit = code.forMoney(money);
        instance.accountCode = code.getCode();
        instance.serviceId = serviceId;
        instance.status = STATUS_VALID;
        instance.commitStatus = COMMIT_STATUS_NO;
        instance.createTime = new Date();
        return instance;
	}
	
	public static LPayAccountHis getCommits(LPayAccount account, double money,
			AccountCode code, long serviceId) {
		LPayAccountHis instance = new LPayAccountHis();
        instance.accountId = account.getId();
        instance.agentId = account.getAgentId();
        instance.debitCredit = code.forMoney(money);
        instance.accountCode = code.getCode();
        instance.serviceId = serviceId;
        instance.status = 2;
        instance.commitStatus = COMMIT_STATUS_NO;
        instance.createTime = new Date();
        return instance;
	}
}